﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.IO;

namespace template_dll
{

   

    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        private string GetServ(string filename)
        {
            string str = "";
            using (StreamReader streamReader = new StreamReader(filename))
            {
                while (!streamReader.EndOfStream)
                {
                    str += streamReader.ReadLine();
                }
            }
            return str;
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            //- Добавление новой маркировки
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //- Занести данные в таблицу
            SqlConnection conn = new SqlConnection(@"Server=" + GetServ("serv.txt") + ";Database=testDM;Integrated Security=True");
            string sstr;
            if (textBox2.Text == null || textBox2.Text == "")
            {
                MessageBox.Show("Не введено название маркировки");
                return;
            }
            sstr = textBox2.Text;
            string sqlString = "INSERT INTO [dbo].[MarkingDM] ( NameMarking ) VALUES ('"+sstr+"');";
            sqlString = String.Format(sqlString);
            SqlCommand sqlCommand = new SqlCommand(sqlString, conn);
            conn.Open();
            sqlCommand.ExecuteNonQuery();
            conn.Close();
            this.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //- Выход без изменений
            this.Close();
        }
    }
}


